<?php
session_start();

require './includes/functions.php';

if (!isset($_SESSION['user'])) {
    redirect_to("../401.php");
}



        if (isset($_GET['id']) && isset($_GET['confirme'])) {

            
 require_once './includes/db.php';
 echo "<link rel=\"stylesheet\" href=\"css/screen.css\" media=\"screen\" />";
 
            $id = $_GET['id'];
            
            if($_GET['confirme'] == "Oui") {
                
                $confirme = 'Non';
                
            } else {
                $confirme = 'Oui';
            }

           
            $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
            $mysqli->set_charset("utf8");
            if ($mysqli->connect_errno) {
                echo "Failed to connect to MySQL with MySQLI: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
            }

           $sql0 = "update and_participant set confirme='$confirme' where id = " . $id;
        

        $mysqli->query($sql0) or die('Problem updating' . $mysqli->errno);
       


        if ($mysqli->affected_rows > 0) {

            echo "<br /><br /><h1 style=\"color: font-family: 'PT Sans Narrow'\"><b style=\"color: yellowgreen;\">Participant confim&eacute;</b></h1><h4>Redirection vers la page participants dans <b><span id='compteur' class='compteur'>";
            ?>

            <script language='javascript'>

                function timestamp(t)
                {
                    document.getElementById("compteur").innerHTML=(t/1000);
                    t-=1000;
                    if(t==0)
                        history.back();
                                                                                        		 
                    setTimeout("timestamp("+t+")",1000);
                }
                window.onload = timestamp(2000);
            </script>
            <?php
            echo "</span></b> secondes</h4><img src='./adm-auth/images/superdroid.png' /></div><div class='bas' id='bas'></div>";
        } else {

            echo "<br /><br /><h1><b style=\"color: rgb(230, 0, 17);\">Erreur de confirmation du participant</b></h1><h4>Redirection vers la page participants dans <b><span id='compteur' class='compteur'>";
            ?>

            <script language='javascript'>

                function timestamp(t)
                {
                    document.getElementById("compteur").innerHTML=(t/1000);
                    t-=1000;
                    if(t==0)
                        history.back();
                                                                                        		 
                    setTimeout("timestamp("+t+")",1000);
                }
                window.onload = timestamp(2000);
            </script>
            <?php
            echo "</span></b> secondes</h4><img src='./adm-auth/images/superdroid.png' /></div><div class='bas' id='bas'></div>";
        }



        $mysqli->close();


          
        } else {
            redirect_to("../401.php");
        }


?>